﻿using System.IO;

namespace sinetd.Utilities
{
    public class Process
    {
        public static string GetExeName()
        {
            return Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location);
        }

        public static void Kill(string name)
        {
            foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses())
            {
                if (p.ProcessName.Contains(name))
                {
                    p.Kill();
                    return;
                }
            }
        }

        public static bool IsOpen(string name, System.Diagnostics.Process proc)
        {
            foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses())
            {
                if (p.ProcessName.Contains(name))
                {
                    proc = p;
                    return true;
                }
            }
            return false;
        }
    }
}
